package cosc617_blackteam;

/**
 * @author Laura
 * A seating strategy that treats tables of units of one and will take unused
 * seats from a partially filled table and will put a party at it if it fits
 */
public class SplitTableSeatingStrategy implements I_SeatingStrategy {
	private TableCollections tableList;

	public SplitTableSeatingStrategy(TableCollections tableList) {
		this.tableList = tableList;
	}

	@Override
	public boolean addParty(CustomerParty party) {
		for (Table table : tableList) {
			// if we are able to add it without splitting do so
			if (table.addCustomerParty(party))
				return true;
			// otherwise
			int availableSeats = table.getTotalSeatingSize()
					- table.countOccupants();
			if (party.getSize() <= availableSeats) {
				// resize the old table to just be that party
				table.size = table.getCustomerParty().getSize();
				Table t = new Table(availableSeats, tableList.getNumTables());
				t.addCustomerParty(party);
				tableList.addTable(t);
				return true;
			}

		}
		return false;
	}

}
